<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core" 
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions"> 

<h:head>
	<title>Cadastro de Usuários</title>
	
	<link rel="stylesheet" href="../../../resources/styles/layout.css" type="text/css"/>
	
	<script type="text/javascript">
		
		/**  
		 * JSF Validator  
		 */
		PrimeFaces.validator['custom.emailValidator'] = {  
      
    	pattern: /\S+@\S+/,  
      
		validate: function(element, value) {  
		        //use element.data() to access validation metadata, in this case there is none.  
		        if(!this.pattern.test(value)) {  
		            throw {  
		                summary: 'Validation Error',  
		                detail: value + ' is not a valid email.'  
		            }  
		        }  
		    }  
		};  
  
		/**  
		 * Bean validator for @Email  
		 */  
		PrimeFaces.validator['Email'] = {  
		      
		    pattern: /\S+@\S+/,  
		              
		    MESSAGE_ID: 'org.primefaces.examples.validate.email.message',  
		      
		    validate: function(element, value) {  
		        var vc = PrimeFaces.util.ValidationContext;  
		  
		        if(!this.pattern.test(value)) {  
		            var msgStr = element.data('p-email-msg'),  
		            msg = msgStr ? {summary:msgStr, detail: msgStr} : vc.getMessage(this.MESSAGE_ID);  
		      
		            throw msg;  
		        }  
		    }  
		};

	</script>
</h:head>

<h:body>
	<h:form id="form1">
	<div class="wrapper row1">
	  <header id="header" class="clear">
	    <hgroup>
	      <h1><a href="index.html">Cardápio Mobile</a></h1>
	      <h2>Seu cardápio para o mundo todo </h2>
	    </hgroup>
			<fieldset class="fl_right">
		    	<p:panel style="width:300px;height:50px;right:200px;top:60px;background:#696969;border:1px solid black">  
			    	<h:outputLabel style="font-weight:bold;color:#FFFFE0;" value="Usuário:"/>
					<h:outputLabel style="font-weight:bold;color:#FFA500;" value="#{loginMB.getSessao('NomeUsuario')}"/>  
					<fieldset>		
						<h:outputLabel value="Restaurante:" style="font-weight:bold;color:#FFFFE0;"/>  
						<h:outputLabel style="font-weight:bold;color:#FFA500;" value="#{loginMB.getSessao('NomeFantasia')}"/>
					</fieldset>  
				</p:panel> 
			</fieldset>
			<fieldset>
			<p></p>
			</fieldset>
			
	    <nav class="clear">
	      <ul>
	        <li class="active"><a href="#">Minha Conta</a>
	          <ul>
	            <li><a href="portalCardapioMundo.jsf">Portal Home</a></li>
	            <li><a href="../user/meusDados.jsf">Meus Dados</a></li>
	            <li><a href="portalCardapioMundo.jsf?changeAccess=EEN013550">Trocar Acesso</a></li>
	            <li onclick="PF(dlgSair).show()"><a href="#">Sair</a></li>
	            <li><a href="#"></a></li>
	          </ul>
	        </li>

	        <li><a href="#">Acesso</a>
	          <ul>
	            <li><a href="cadUsuario.jsf">Novo Usuário</a></li>
	            <li><a href="../user/consUsuario.jsf">Consulta Usuários</a></li>
	            <li><a href="#"></a></li>
	          </ul>
	        </li>
	        
	        <li><a href="#">Restaurante</a>
	          <ul>
	            <li><a href="#">Novo Restaurante</a></li>
	            <li><a href="#">Restaurantes</a></li>
	            <li><a href="#"></a></li>
	          </ul>
	        </li>

	        <li><a href="#">Cardápio</a>
	          <ul>
	            <li><a href="#">Novo Cardápio</a></li>
	            <li><a href="#">Cardápios</a></li>
	            <li><a href="#"></a></li>
	          </ul>
	        </li>

	        <li><a href="#">Business Intelligence</a>
	          <ul>
	            <li><a href="#">Avaliações Cardápio</a></li>
	            <li><a href="#">Avaliações Atendimento</a></li>
	            <li><a href="#">Avaliações Infraestrutura</a></li>
	            <li><a href="#">Avaliação Geral</a></li>
	            <li><a href="#"></a></li>
	          </ul>
	        </li>

	        <li><a href="#">Pagamento</a>
	          <ul>
	            <li><a href="#">Meus Pagamentos</a></li>
	          </ul>
	        </li>
	        <li><a href="#">Plano</a>
	          <ul>
	            <li><a href="#">Meu Plano</a></li>
	            <li><a href="#">Renovação</a></li>
	            <li><a href="#">Novos Planos</a></li>
	          </ul>
	        </li>
	        
	      </ul>
	    </nav>
	  </header>
	</div>
	
	<p:dialog id="dialogSair" header="Opção Logout" modal="true" height="85" width="510" widgetVar="dlgSair" resizable="false" 
	showEffect="fade" hideEffect="fade">  
		<h:panelGrid columns="2" cellpadding="5">  
			<h:outputLabel for="username" value="Deseja desconectar do portal Cardápio Mobile ?" style="font-size:15px"/>
		</h:panelGrid>
				          
		<f:facet name="footer">  
			<p class="fl_left">
			<p:commandButton id="cancelarButton" value="Cancelar" height="50" width="50" onclick="PF(dlgSair).hide();"/>
			</p>
			<p class="fl_right">
				<p:commandButton id="sairButton" value="Sair" height="50" width="50" actionListener="#{acessoMB.logout}"/>
			</p>  
		</f:facet>  
    </p:dialog>
	</h:form>
	
<!-- ########################################################################################## -->

	<div class="wrapper row2">
	    <div id="container" class="clear"> 
	    <div id="homepage"> 
	    	<h:form id="form">
				<p:panel header="Dados do Usuário de Acesso">  
					<p:messages id="messages" showDetail="false" autoUpdate="true" closable="true" /> 
					<h:messages />
				
	        		<h:panelGrid id="grid0" columns="2" border="0" cellpadding="10">
						 	<h:outputText for="nome" value="#{msgs.nomeUsuario}"/>
					        <p:inputText id="nome" size="30" value="#{usuarioMB.usuario.nome}" required="true" label="#{msgs.dNomeUsuario}">
						        	<f:validateLength minimum="3" maximum="15" />
					        </p:inputText> 
	
							<h:outputText for="sobrenome" value="#{msgs.sobrenomeUsuario}"/>
						    <p:inputText id="sobrenome" value="#{usuarioMB.usuario.sobrenome}" required="true" label="#{msgs.dSobrenomeUsuario}">  
						        	<f:validateLength minimum="3" maximum="20" />
						    </p:inputText> 
						    
						    
	    					<h:outputText for="cpf" value="#{msgs.CPF}" />
			            	<p:inputMask id="cpf" value="#{usuarioMB.usuario.cpf}" required="true" label="#{msgs.dCPF}"
			            	 maxlength="11" converter="retiraMaskConverter" mask="999.999.999-99">
								 <f:validator validatorId="validator.CpfValidator" /> 
							</p:inputMask> 


			            	<h:outputText for="mail" value="#{msgs.emailUsuario}" />
			            	<p:inputText id="mail" value="#{usuarioMB.usuario.mail}" required="true" label="#{msgs.dEmailUsuario}"
			            		validatorMessage="Formato de E-mail invalido">  
								<f:validateRegex pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
							</p:inputText> 


		            		<h:outputText for="descPerfil" value="#{msgs.perfilUsuario}" />
		            		<h:selectOneMenu id="descPerfilAdmRestaurante" value="#{usuarioMB.descPerfil}" rendered="#{usuarioMB.perfilSessao == 'ADMIN.RESTAURANTE'}" required="true" label="#{msgs.dPerfilPermitidoUsuario}">
	            				<f:selectItem itemLabel="Select One" itemValue=""/>
	            				<f:selectItem itemLabel="Usuário" itemValue="USUARIO"/>
					        </h:selectOneMenu>
					        
					        <h:selectOneMenu id="descPerfilAdmConta" value="#{usuarioMB.descPerfil}" rendered="#{usuarioMB.perfilSessao == 'ADMIN.CONTA'}" required="true" label="#{msgs.dPerfilPermitidoUsuario}">
	            				<f:selectItem itemLabel="Select One" itemValue=""/>
	            				<f:selectItem itemLabel="Admin.Restaurante" itemValue="ADMIN.RESTAURANTE"/>
	            				<f:selectItem itemLabel="Usuario" itemValue="USUARIO"/>
					        </h:selectOneMenu>
					        
		            </h:panelGrid> 
		            
					<h:panelGrid id="grid1" columns="2" border="0" cellpadding="10" rendered="#{acessoMB.restauranteSource.size() > 0}">
		            
			    		<p:pickList id="restaurante" value="#{acessoMB.restaurantePickView}"
			            			  var="acessoWeb"  effect="bounce" itemValue="#{acessoWeb}" 
			            			  style="width:50%;" converter="restaurantePickListConverter">
										 
							<f:facet name="sourceCaption">Restaurante/Matriz</f:facet>  
		        			<f:facet name="targetCaption">Permissão Acesso</f:facet>  
		        
							<p:ajax event="transfer" listener="#{acessoMB.onTransferRestaurante}"/>
											 
							<p:column style="width:60%;">  
		            			#{acessoWeb.restauranteWeb.nomeFantasia}
		        			</p:column>
						</p:pickList>
					</h:panelGrid>		            
		            		            
		            <h:panelGrid id="grid2" columns="2" border="0" cellpadding="10" rendered="#{acessoMB.perfilSessao == 'ADMIN.CONTA'}">

		            			<p:pickList id="filiaisAdmConta" value="#{restauranteFilialMB.filiais}"
		            			  var="restFilialWeb"  effect="bounce" itemValue="#{restFilialWeb}" style="width:50%;" 
		            			  converter="filialPickListConverter">
									 
										<f:facet name="sourceCaption">Restaurante/Filiais</f:facet>  
	        							<f:facet name="targetCaption">Permissão Acesso</f:facet>  
	        
		 								 <p:ajax event="transfer" listener="#{restauranteFilialMB.onTransfer}" /> 
										 
										 <p:column style="width:60%;">  
	            							#{restFilialWeb.nomeFantasiaFilial} 
	        							 </p:column>
								</p:pickList>
					</h:panelGrid>

		            <h:panelGrid id="grid3" columns="2" border="0" cellpadding="10" rendered="#{acessoMB.perfilSessao == 'ADMIN.RESTAURANTE'}">

		            			<p:pickList id="filiaisAdmRestaurante" value="#{acessoMB.filiaisAdmRest}"
		            			  var="acessoWeb"  effect="bounce" itemValue="#{acessoWeb}" style="width:50%;" 
		            			  converter="perfilAdmPickListConverter">
									 
										<f:facet name="sourceCaption">Restaurante/Filiais</f:facet>  
	        							<f:facet name="targetCaption">Permissão Acesso</f:facet>  
	        
		 								 <p:ajax event="transfer" listener="#{acessoMB.onTransfer}" /> 
										 
										 <p:column style="width:60%;">  
	            							#{acessoWeb.restauranteFilialWeb.nomeFantasiaFilial} 
	        							 </p:column>
								</p:pickList>
					</h:panelGrid>
						
					<h:panelGrid id="grid4" columns="2" border="0" cellpadding="5">
					       	
			            		<h:outputText for="usuarioUsuario" value="#{msgs.usernameUsuario}"/>
			            		<p:inputText id="usuarioUsuario" value="#{usuarioMB.usuario.username}" required="=true" label="#{msgs.dUsernameUsuario}">  
						        	<f:validateLength minimum="5" maximum="15" />
						        </p:inputText> 
	
			            		<h:outputText for="passwordAcesso" value="#{msgs.senhaUsuario}"/>
			            		<p:password id="passwordAcesso" feedback="true" required="true" value="#{usuarioMB.usuario.password}" match="confirmaSenha" label="#{msgs.dSenhaUsuario}">  
						        	<f:validateLength minimum="5" maximum="15" />
						        </p:password> 
	
			              		<h:outputText for="confirmaSenha" value="#{msgs.confirmaSenhaUsuario}"/>
			            		<p:password id="confirmaSenha" feedback="true" required="true" value="#{usuarioMB.usuario.password}" label="#{msgs.dConfirmaSenhaUsuario}">  
						        	<f:validateLength minimum="5" maximum="15" />
						        </p:password> 
			         </h:panelGrid>
           		</p:panel>
           		
	        	<p:panelGrid columns="1" style="margin-bottom:0px;">  
		        	  <f:facet name="footer">	  
		        			<p class="fl_left">
		        				<p:commandButton  value="#{msgs.limpar}" icon="ui-icon-check" type="reset" immediate="true" update="grid,grid2" />
		        			</p>  
							<p class="fl_right">
								<p:commandButton value="#{msgs.salvar}" 
			        			icon="ui-icon-check" action="#{usuarioMB.salvarUsuarioPerfilAdmConta}" validateClient="true"
			        			rendered="#{acessoMB.perfilSessao == 'ADMIN.CONTA'}"/>
			        			
								<p:commandButton  update="grid0,grid1,grid3,grid4" value="#{msgs.salvar}" icon="ui-icon-check" 
			        			actionListener="#{usuarioMB.salvarUsuarioPerfilAdmRestaurante}" validateClient="true" 
			        			rendered="#{acessoMB.perfilSessao == 'ADMIN.RESTAURANTE'}"/>
							</p>
		    			</f:facet>
	    		</p:panelGrid>
	    	</h:form>
      </div>
	  </div>
	</div>

	<!-- Copyright -->
	<div class="wrapper row4">
	  <footer id="copyright" class="clear">
	    <p class="fl_left">Copyright 2014 - All Rights Reserved - <a href="#">W7VM</a></p>
	    <p class="fl_right">W7VM <a href="http://www.w7vm.com/" title="Developer Application Mobile">Developer Application Mobile</a></p>
	  </footer>
	</div>
</h:body>
</html>